package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.EmployeeMapper;
import com.gxa.modules.pojo.Employee;
import com.gxa.modules.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired(required = false)
    private EmployeeMapper employeeMapper;

    @Override
    public JsonResult queryEmployee(Integer page, Integer limit) {


        JsonResult r=new JsonResult();
        Integer parma1=(page-1)*limit;
        Integer parma2=limit;
        Integer count=employeeMapper.findCount();
        List<Map> employeeList = employeeMapper.queryEmployee(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(employeeList);
        return r;
    }

    @Override
    public ResultVo addEmployee(Employee employee) {

        employeeMapper.addEmployee(employee);
        ResultVo r =new ResultVo();
        r.setCode(200);
        r.setMsg("添加成功");
        return  r;
    }

    @Override
    public ResultVo delEmployee(List<Integer> employee_numbers) {
        ResultVo r =new ResultVo();
        r.setCode(200);
        r.setMsg("删除成功");
        employeeMapper.delEmployee(employee_numbers);
        return r;
    }

    @Override
    public JsonResult searchEmployee(Integer page, Integer pageSize, String search) {
        System.out.println("page"+page);
        System.out.println("pageSize"+pageSize);
        System.out.println("search"+search);
        JsonResult r=new JsonResult();
        Integer parma1=(page-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=employeeMapper.findCountSearch(search);
        List<Employee> employeeList = employeeMapper.searchEmployee(parma1,parma2,search);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(employeeList);
        return r;
    }
}
